#include "StdAfx.h"
#include "MySocket.h"

CMySocket::CMySocket(void)
{
}

CMySocket::~CMySocket(void)
{
}


int CMySocket::SendCommand(SOCKET socket,const char* buf,int bytes)
{
	const char *b = buf;
	while(bytes > 0) 
	{ 
		int r = send(socket,b,bytes,0); 
		if(r < 0) 
		{ 
			return r; 
		} 
		else if(r == 0)
		{
			break;
		} 
		bytes -= r; 
		b += r; 
	} 
	return b - (char*)buf;
}

int CMySocket::RecvCommand(SOCKET socket,char* buf,int bytes)
{
	char *b = (char*)buf;
	while(bytes > 0)
	{
		int r = recv(socket,b,bytes,0);
		if(r < 0)
		{
			return 0;
		}
		else if(r == 0)
		{
			break;
		}
		bytes = bytes - r;
		b = b + r;
	}
	return b - (char*)buf;
}


void CMySocket::Clean()
{
	::WSACleanup();
}